﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Pages_changeProfile : System.Web.UI.UserControl
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["UserName"] != null)
            {
                mvwChangeProfile.ActiveViewIndex = 0;
                Session["Password"] = Request.Cookies["Register"]["Password"];
                txtUserName.Text = Request.Cookies["Register"]["Username"];
                txtFullName.Text = Request.Cookies["Register"]["Fullname"];
                txtEmail.Text = Request.Cookies["Register"]["Email"];
                if (Request.Cookies["Register"]["Gender"] == "Male")
                {
                    rdbMale.Checked = true;
                }
                else
                {
                    rdbFeMale.Checked = false;
                }
            }
            else
            {
                lbChangProflieStatus.Text = "You are not sign in. Please login!";
                mvwChangeProfile.ActiveViewIndex = 1;
            }
        }
    }
    protected void btUpadte_Click(object sender, EventArgs e)
    {
        HttpCookie register = new HttpCookie("Register");
        register.Values["Fullname"] = txtFullName.Text;
        register.Values["UserName"] = txtUserName.Text;
        register.Values["Password"] = Session["Password"].ToString();
        register.Values["Email"] = txtEmail.Text;
        if (rdbMale.Checked)
        {
            register.Values["Gender"] = "Male";
        }
        else
        {
            register.Values["Gender"] = "Female";
        }
        register.Values["Gender"] = "Male";
        Response.Cookies.Add(register);

        Session["UserName"] = txtFullName.Text;        

        lbChangProflieStatus.Text = "Change profile successed!";        
        mvwChangeProfile.ActiveViewIndex = 1;
    }
    protected void btChangeProfleOk_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/Default.aspx");
    }
}